<?
include("../lib/config.php");
$nik 	= $HTTP_GET_VARS['nik'];
$op		= $HTTP_GET_VARS['op'];
//$no		= $HTTP_GET_VARS['no'];
$tahun	= $HTTP_GET_VARS['tahun'];
//$nama	= $HTTP_GET_VARS['nama'];

if($op == "edit"){
	$Faction = "../lib/update.php";
	$Vbutton = "Update";
	$query	= mssql_query("WITH limit AS (SELECT ROW_NUMBER() OVER (ORDER BY NIK) AS No, * FROM VPenilaian WHERE NIK='$nik' ) SELECT * FROM limit WHERE No='$no'",$conn);
	$row	= mssql_fetch_array($query);
}
else{
	$Faction = "../lib/save.php";
	$Vbutton = "Save";
}

include("../header.php");
?>
<script type="text/javascript">
	
	MaskInput = function(f, m){
	function mask(e){
		var patterns = {"1": /[A-Z]/i, "2": /[0-9]/, "4": /[\xC0-\xFF]/i, "8": /./ },
			rules = { "a": 3, "A": 7, "9": 2, "C":5, "c": 1, "*": 8};
		function accept(c, rule){
			for(var i = 1, r = rules[rule] || 0; i <= r; i<<=1)
				if(r & i && patterns[i].test(c))
					break;
				return i <= r || c == rule;
		}
		var k, mC, r, c = String.fromCharCode(k = e.key), l = f.value.length;
		(!k || k == 8 ? 1 : (r = /^(.)\^(.*)$/.exec(m)) && (r[0] = r[2].indexOf(c) + 1) + 1 ?
			r[1] == "O" ? r[0] : r[1] == "E" ? !r[0] : accept(c, r[1]) || r[0]
			: (l = (f.value += m.substr(l, (r = /[A|9|C|\*]/i.exec(m.substr(l))) ?
			r.index : l)).length) < m.length && accept(c, m.charAt(l))) || e.preventDefault();
	}
	for(var i in !/^(.)\^(.*)$/.test(m) && (f.maxLength = m.length), {keypress: 0, keyup: 1})
		addEvent(f, i, mask);
};

	function Validate(){

		if(document.forms[0].nik.value == ""){
			alert("Maaf, NIK tidak boleh kosong ...");
			document.forms[0].nik.focus();
			return false;
		}

		if(document.forms[0].tahun.value == ""){
			alert("Maaf, Tahun tidak boleh kosong ...");
			document.forms[0].tahun.focus();
			return false;
		}
		
		if(document.forms[0].unsur.value == ""){
			alert("Maaf, Unsur Penilaian harus dipilih ...");
			document.forms[0].unsur.focus();
			return false;
		}
		
		if(document.forms[0].nilai1.value == ""){
			alert("Maaf, Nilai 1 harus dipilih ...");
			document.forms[0].nilai1.focus();
			return false;
		}
		
		if(document.forms[0].nilai2.value == ""){
			alert("Maaf, Nilai 2 harus dipilih ...");
			document.forms[0].nilai2.focus();
			return false;
		}


		if(document.forms[0].nilai3.value == ""){
			alert("Maaf, Nilai 3 harus dipilih ...");
			document.forms[0].nilai3.focus();
			return false;
		}
		
		if(document.forms[0].cat_penilai.value == ""){
			alert("Maaf, Kategori penilaian harus dipilih ...");
			document.forms[0].cat_penilai.focus();
			return false;
		}
		
		document.forms[0].submit();
	}
	
	function show_popup(page)
	{
		child = open
		(
			"frm_list_emp.php",
			"",
			"scrollbars,width=400,height=400,left=150,top=150"
		);
	}
</script>
</head>
<table width="93%" class="table_indent2">
 <tr>
  <td class="line_bottom">&nbsp;&nbsp;<b>PENILAIAN KARYAWAN</b></td>
 </tr>
</table>
<?
// get nama
	$sN	= mssql_query("SELECT B.NIK, B.Nama, periode FROM S_LP A, Karyawan B WHERE A.NIK=B.NIK AND A.NIK='$nik' AND periode='$tahun'",$conn);
	$rN = mssql_fetch_array($sN);
// get jabatan / unit kerja
	$sJu = mssql_query("SELECT uraian unit_kerja, AreaCode, C.jabatan Jabatan, nama nama_jabatan FROM KaryawanStatus A, MstSO B, MstJabatan C WHERE A.kode_so=B.kode_so AND A.jabatan=C.kode AND NIK='$nik'",$conn);
	$rJu = mssql_fetch_array($sJu);
?>
<table width="100%">
<tr>
 <td colspan="2">
  &nbsp;<b>Karyawan Yang dinilai:</b><hr noshade="noshade" size="-2" color="#999999" />
 </td>
</tr>
 <tr>
  <td colspan="2">
   <table>
    <tr>
	 <td width="110">NIK</td>
	 <td><input type="text" name="nik" value="<?=$rN[NIK]?>" readonly=""/>
	<?
		if($HTTP_GET_VARS['nik'] == NULL ){
			echo"<a href='Javascript:show_popup()'><img src='../images/people.png' border=0></a>";
		}
	?>
	 </td>
	</tr>
    <tr>
	 <td>Nama</td>
	 <td><input type="text" name="nama" size="45" value="<?=$rN[Nama]?>" readonly="" /></td>
	</tr>
	 <tr>
	  <td>Periode Tahun</td>
	  <td><input type="text" name="tahun" size="4" value="<? if($op == "edit") { echo"$row[tahun]"; } else { echo"$tahun"; } ?>" readonly="" /> </td>
	 </tr>
	 <tr>
	  <td>Jabatan</td>
	  <td><input type="text" name="nama" size="45" value="<?=$rJu[Jabatan]?>" readonly="" /></td>
	 </tr>
	 <tr>
	  <td>Unit Kerja</td>
	  <td><input type="text" name="nama" size="45" value="<?=$rJu[unit_kerja]." - ".$rJu[AreaCode]?>" readonly="" /></td>
	 </tr>	 
   </table>
  </td>
 </tr>
 <tr>
  <td colspan="2"><hr noshade="noshade" size="-2"/></td>
 </tr>
 <tr>
  <td>
<form target="_parent" action="../lib/save.php" method="post">
<input type="hidden" name="nik" value="<?=$nik?>">
<input type="hidden" name="tahun" value="<?=$tahun?>">
<input type="hidden" name="cat" value="lp_detail" />
<input type="hidden" name="cat_penilai" value="<?=$HTTP_GET_VARS['tipe']?>">

<?
	if($HTTP_GET_VARS['tipe'] == "adum"){
?>
	<fieldset>
     <legend>Tabel Penilaian <?=strtoupper($HTTP_GET_VARS['tipe'])?></legend>
     <table>
      <tr class="headlist">
       <td>No.</td>
       <td>Kriteria Penilaian</td>
       <td colspan="2">Nilai</td>
      </tr>
      <tr class="contentlist">
       <td>1</td>
       <td>Tidak pernah dikenakan sanksi dalam bentuk apapun dan tidak terdapat catatan dalam presensi (keterlambatan, pulang cepat, dll/catatan presensi bersih dalam periode penilaian, kecuali dinas, sakit dan cuti).</td>
       <td>5</td>
       <td><input type="radio" name="nilai" value="5" checked="checked" /></td>
      </tr>
      <tr class="contentlist">
       <td>2</td>
       <td>Tidak pernah diberikan sanksi, tetapi karena sesuatu hal kadang-kadang terlambat masuk, tetapi tidak melampaui batas/jumlah
toleransi yang ditentukan perusahaan/presensi kerja tidak bersiih dari catatan keterlambatan dll, kecuali dinas, cuti, dan sakit dalam periode penilaian.</td>
       <td>4</td>
       <td><input type="radio" name="nilai" value="4" /></td>
      </tr>
      <tr class="contentlist">
       <td>3</td>
       <td>Pernah dikenakan sanksi TEGURAN LISAN TERCATAT atau TEGURAN TERTULIS.</td>
       <td>3</td>
       <td><input type="radio" name="nilai" value="3" /></td>
      </tr>
      <tr class="contentlist">
       <td>4</td>
       <td>Pernah diberikan sanksi berupa SURAT PERINGATAN I (SP-1) dan atau SP II.</td>
       <td>2</td>
       <td><input type="radio" name="nilai" value="2" /></td>
      </tr>
      <tr class="contentlist">
       <td>5</td>
       <td>Pernah diberikan sanksi berupa SANKSI PERINGATAN III dan atau SANKSI BERAT (Penurunan Golongan
dan atau pembebasan Jabatan Struktural/Fungsional).</td>
       <td>1</td>
       <td><input type="radio" name="nilai" value="1" /></td>
      </tr>
     </table>
    </fieldset>
    <center>
  <input type="hidden" value="<?=$_SESSION['user_login']?>" name="penilai" />
  <input type="hidden" name="cat" value="lp_detail" />
  <input type="hidden" name="no" value="<?=$row[No]?>" />
  <input type="button" value="Batal" class="button" onClick="Javascript:history.back();" />
  <input type="submit" value="Simpan" class="button" />
  </center>
  </form>
<?	
	}
	else{
?>

<fieldset><legend><b>Tabel Penilaian <?=strtoupper($HTTP_GET_VARS['tipe'])?></b></legend>
<table>
 <tr class="headlist">
  <td>No.</td>
  <td>Unsur Penilaian</td>
  <td>Nilai</td>
 </tr>
 <?
	include("../lib/config.php");
    $sUnsur = mssql_query("SELECT ROW_NUMBER() OVER (ORDER BY unsur_penilai)-1 AS No , unsur_penilai, unsurName FROM MstUnsurLP2 A, S_LP_Cat_Nilai B WHERE B.unsur_penilai=A.UnsurID AND category='".$HTTP_GET_VARS['tipe']."' ORDER BY unsurID ASC",$conn);
	while($rUnsur = mssql_fetch_array($sUnsur)){
		echo"
		<tr class=contentlist>
		 <td align=right>".($rUnsur[No]+1)."</td>
		 <td>
			<input type='hidden' value='".$rUnsur[unsur_penilai]."' name='id_unsur[]'>
			$rUnsur[unsurName]
		 </td>
		 <td>";
		 for($j=1;$j<=5;$j++){
		 	if($j == 1){
				echo'
				&nbsp;&nbsp;&nbsp;&nbsp;
				<input type="radio" name="NN_'.$rUnsur[No].'" value="'.$j.'" checked />'.$j.'
				&nbsp;&nbsp;&nbsp;';
			}
			else{
				echo'
				<input type="radio" name="NN_'.$rUnsur[No].'" value="'.$j.'" />'.$j.'
				&nbsp;&nbsp;&nbsp;';
			}
		 }
		 echo"</td>
		</tr>
		";
	}
	
 ?>
 <tr>
  <td colspan="3" style="font-size:10px;">
  <b>Catatan:</b><br />
  <textarea cols="90" rows="3" name="catatan"><?=$row[catatan]?></textarea>
  <input type="hidden" value="<?=$_SESSION['user_login']?>" name="penilai" />
  </td>
 </tr>
 <tr>
  <td colspan="3" align="right">
  <input type="hidden" name="cat" value="lp_detail" />
  <input type="hidden" name="no" value="<?=$row[No]?>" />
  <input type="button" value="Batal" class="button" onClick="Javascript:history.back();" />
  <input type="submit" value="Simpan" class="button" />
  </td>
 </tr>
 </table>
 </fieldset>
 </form>  
 </td>
 </tr>
 </table>
 <?
 }
 ?>
 </td>
 </tr>
</table>

</td>
</tr>
</table>
</body>
<script type="text/javascript">

var f = document.forms[0];
MaskInput(f.tahun,"9999");
//]]>
</script>
<?
echo"</div>
	  </td>
	   </tr>
	    </table>
";
include("../menu.php");
?>
